﻿<UserControl x:Class="LatestChatty.Controls.CommentListControl"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:chatty="clr-namespace:LatestChatty.Classes"
	xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
	mc:Ignorable="d"
	FontFamily="{StaticResource PhoneFontFamilyNormal}"
	FontSize="{StaticResource PhoneFontSizeNormal}"
	Foreground="#FFFFFF"
	d:DesignHeight="480" d:DesignWidth="480">

	<Grid x:Name="LayoutRoot" Grid.Row="1" Margin="0,0,0,0">
		<ListBox Margin="0,0,0,0" x:Name="commentListBox" ItemsSource="{Binding Comments}" SelectionChanged="SelectionChanged">
			<ItemsPanelTemplate>
				<StackPanel/>
			</ItemsPanelTemplate>
			<ListBox.ItemTemplate>
				<DataTemplate>
					<Grid>
						<Grid Visibility="{Binding IsLoadMoreComment, Converter={StaticResource BoolToVisConverter}}">
							<Button Click="LoadMore_Click" Style="{StaticResource LoadMoreButton}" Content="load more..." Width="455" />
						</Grid>
						<Grid Visibility="{Binding IsLoadMoreComment, Converter={StaticResource NotBoolToVisConverter}}">
							<StackPanel Width="455">
								<Grid>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="Auto"/>
										<ColumnDefinition Width="*"/>
									</Grid.ColumnDefinitions>
									<TextBlock HorizontalAlignment="Left" Text="{Binding author}" FontSize="20" Foreground="#ffba00"/>
									<TextBlock Grid.Column="1" HorizontalAlignment="Right" Text="{Binding dateText}" FontSize="20" Foreground="#888888"/>
								</Grid>

								<Grid>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="40"/>
										<ColumnDefinition Width="*"/>
									</Grid.ColumnDefinitions>
									<!--Reply Count, etc-->
									<Border Grid.Column="0" Margin="0,10,0,10" Background="{Binding category, Converter={StaticResource CategoryConverter}}">
										<Grid>
											<!--Have I participated?-->
											<Grid VerticalAlignment="Top" 
												Height="15"
												Visibility="{Binding IsCollapsed, Converter={StaticResource NotBoolToVisConverter}}">
												<Rectangle 
												  Fill="{StaticResource PhoneAccentBrush}" 
												  Visibility="{Binding selfReply, Converter={StaticResource BoolToVisConverter}}" />
											</Grid>

											<!--How many replies-->
											<TextBlock 
												  HorizontalAlignment="Center" 
												  VerticalAlignment="Center" 
												  Text="{Binding reply_count}" 
												  FontSize="20" 
												  Foreground="#000000" 
												  FontWeight="Bold"/>
											<!--Is it pinned?-->
											<Grid Height="10"
												Width="10"
												HorizontalAlignment="Left"
												VerticalAlignment="Bottom"
												Visibility="{Binding IsCollapsed, Converter={StaticResource NotBoolToVisConverter}}">
												<Rectangle 
												  
												  Fill="{StaticResource PhoneAccentBrush}"
												  Visibility="{Binding IsPinned, Converter={StaticResource BoolToVisConverter}}" />
											</Grid>
										</Grid>
									</Border>
									<!--Post Preview Message - Not Collapsed-->
									<TextBlock Grid.Column="1" 
											  Height="84"
											  TextWrapping="Wrap" 
											  Style="{StaticResource PhoneTextNormalStyle}" 
											  Foreground="{Binding HasNewReplies, Converter={StaticResource NewReplyConverter}}"
											  Visibility="{Binding IsCollapsed, Converter={StaticResource NotBoolToVisConverter}}"
											  Text="{Binding preview}" />
									<!--Post Preview Message - Collapsed-->
									<TextBlock Grid.Column="1" 
											  Height="35"										  
											  TextWrapping="NoWrap" 										  
											  Style="{StaticResource PhoneTextNormalStyle}" 
											  Foreground="{Binding HasNewReplies, Converter={StaticResource NewReplyConverter}}"
											  Visibility="{Binding IsCollapsed, Converter={StaticResource BoolToVisConverter}}"
											  Text="{Binding preview}" />
								</Grid>
							</StackPanel>
							<Grid Grid.Column="0" Grid.ColumnSpan="2" Background="Black" Opacity=".6" Visibility="{Binding IsCollapsed, Converter={StaticResource BoolToVisConverter}}" />
							<toolkit:ContextMenuService.ContextMenu>
								<toolkit:ContextMenu>
									<toolkit:MenuItem Header="unpin" Click="TogglePin_Click" Visibility="{Binding IsPinned, Converter={StaticResource BoolToVisConverter}}"/>
									<toolkit:MenuItem Header="pin" Click="TogglePin_Click" Visibility="{Binding IsPinned, Converter={StaticResource NotBoolToVisConverter}}"/>
									<toolkit:MenuItem Header="uncollapse" Click="ToggleCollapsed_Click" Visibility="{Binding IsCollapsed, Converter={StaticResource BoolToVisConverter}}"/>
									<toolkit:MenuItem Header="collapse" Click="ToggleCollapsed_Click" Visibility="{Binding IsCollapsed, Converter={StaticResource NotBoolToVisConverter}}"/>
								</toolkit:ContextMenu>
							</toolkit:ContextMenuService.ContextMenu>
						</Grid>
					</Grid>
				</DataTemplate>
			</ListBox.ItemTemplate>
		</ListBox>
	</Grid>
</UserControl>
